<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Try it</title>
  </head>
  <body>
    <img
      src="try-it-tick.jpg"
      alt="tick"
      onmouseover="this.src='try-it-tick2.jpg'"
    />
    <script>
      // ---------------------------------------------------
      function addTax(subtotal, taxRate) {
        const total = subtotal * (1 + taxRate / 100);
        return total;
      }

      const invoiceValue = addTax(50, 100);
      alert(invoiceValue);
      alert(total);

      // ---------------------------------------------------
      const a = 10;
      var b = 10;

      function showVars() {
        const a = 20;
        b = 20;
        return "Local varibale 'a' = " + a + "\nGlobal variable'b' = " + b;
      }

      const message = showVars();
      alert(message + "\nGlobal variable'a' = " + a);

      // ---------------------------------------------------
      function myFunction(x) {
        let y = x;
        if (x > 50) {
          let y = 10;
          alert('Inner y = ' + y);
        }
        alert('Outer y = ' + y);
      }

      myFunction();

      // ---------------------------------------------------
      function myFunction2() {
        const x = 300;
        x = 400;
      }

      myFunction2();

      // ---------------------------------------------------
      const sayHello = () => alert('Hello');
      const myFunc = x => alert(x);
      const myFunc2 = (x, y) => alert(x + y);
      const myFunc3 = (x, y, z) => {
        let area = x * y + 5;
        let boxes = area / z;
        return boxes;
      };

      // ---------------------------------------------------
      function warn(temp) {
        alert('Warning:\nA Temperature of ' + temp + ' is too high');
      }

      warn(95);

      function warn2(temp, headline = 'Warning') {
        alert(headline + ':\nA Temperature of ' + temp + ' is too high');
      }

      warn2(95);
      warn2(105, '***DANGER***');
    </script>
  </body>
</html>
